/*
 * Copyright 2009 Armando Blancas
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package taskgraph.tasks;

import java.util.Iterator;

/**
 * A task whose work cannot be subdivided.
 * <p>
 * Subclasses are scheduled to run each in its own thread.
 * 
 * @author Armando Blancas
 */
public abstract class PrimitiveTask extends Task { 

	/**
	 * Gets a list iterator that has no elements. This way primitive tasks
	 * can be used in generic code without branching on type.
	 * 
	 * @return An empty {@code ListIterator}.
	 */
	@Override
	public Iterator<Task> iterator() {
		return new Iterator<Task>() {
			public boolean hasNext() { return false; }
			public Task next() { return null; }
			public void remove() { }
		};
	}

	/**
	 * Performs some setup work before the task executes.
	 * It will most usually be empty but it is here to support code that works
	 * with objects of type Task.
	 */
	@Override
    protected void setup() {
    	// Optional for primitive tasks.
    }
}
